home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / usbcreator / wrap_label.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.8 KB  |  61 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import gobject
  5. import pygtk
  6. import gtk
  7. import pango
  8.  
  9. class WrapLabel(gtk.Label):
  10.     __gtype_name__ = 'WrapLabel'
  11.     
  12.     def __init__(self, text = ''):
  13.         gtk.Label.__init__(self)
  14.         self.m_wrap_width = 0
  15.         self.get_layout().set_wrap(pango.WRAP_WORD_CHAR)
  16.         self.set_alignment(0, 0)
  17.         self.set_markup(text)
  18.         self.connect('size-request', self.on_size_request)
  19.         self.connect('size-allocate', self.on_size_allocate)
  20.  
  21.     
  22.     def set_text(self, text):
  23.         gtk.Label.set_text(self, text)
  24.         self.set_wrap_width(self.m_wrap_width)
  25.  
  26.     
  27.     def set_markup(self, text):
  28.         gtk.Label.set_markup(self, text)
  29.         self.set_wrap_width(self.m_wrap_width)
  30.  
  31.     
  32.     def on_size_request(self, widget, requisition):
  33.         (width, height) = self.get_layout().get_pixel_size()
  34.         requisition.width = 0
  35.         requisition.height = height
  36.  
  37.     
  38.     def on_size_allocate(self, widget, allocation):
  39.         gtk.Label.size_allocate(self, allocation)
  40.         self.set_wrap_width(allocation.width)
  41.  
  42.     
  43.     def set_wrap_width(self, width):
  44.         if width == 0:
  45.             return None
  46.         self.get_layout().set_width(width * pango.SCALE)
  47.         if self.m_wrap_width != width:
  48.             self.m_wrap_width = width
  49.             self.queue_resize()
  50.         
  51.  
  52.  
  53. gobject.type_register(WrapLabel)
  54. if __name__ == '__main__':
  55.     w = gtk.Window(gtk.WINDOW_TOPLEVEL)
  56.     l = WrapLabel("This is a very long label that should span many lines. It's a good example of what the WrapLabel can do, and includes formatting, like <b>bold</b>, <i>italic</i>, and <u>underline</u>. The window can be wrapped to any width, unlike the standard Gtk::Label, which is set to a certain wrap width.")
  57.     w.add(l)
  58.     w.show_all()
  59.     gtk.main()
  60.  
  61.